﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using NC.Infrastructure.Data;
using domainEntity=NC.Infrastructure.Domain.Record.ApiRecord;

namespace NC.Service.ApiRecord
{
    public class ApiRecordService:IApiRecordService
    {
        private readonly IRepository<domainEntity> _apiRecordRepository;

        public ApiRecordService(IRepository<domainEntity> apiRecordRepository)
        {
            this._apiRecordRepository = apiRecordRepository;
        }

        public domainEntity Get(int id)
        {
            return _apiRecordRepository.Entities.Include("Person", "Target").FirstOrDefault(n => n.Id == id);
        }

        public IQueryable<domainEntity> GetAll()
        {
            return _apiRecordRepository.Entities;
        }

        public IQueryable<domainEntity> Get(Expression<Func<domainEntity, bool>> filter)
        {
            return _apiRecordRepository.Get(filter);
        }

        public void Insert(domainEntity entity)
        {
            _apiRecordRepository.Insert(entity);
        }

        public void Update(domainEntity entity)
        {
            _apiRecordRepository.Update(entity);
        }

        public void Delete(domainEntity entity)
        {
            _apiRecordRepository.Delete(entity);
        }

        public void Commit()
        {
            _apiRecordRepository.Commit();
        }
    }
}
